package com.zsc.wxm.ysh.anjo.es.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 描述： es 配置
 *
 * @author playmaker
 * @since 2021/2/14 23:54
 */
@Configuration
@Slf4j
public class EsClientConfig {

    /**
     * 配置高级客户端
     * @return
     */
    @Bean
    public RestHighLevelClient restHighLevelClient() {
        RestClientBuilder builder = RestClient.builder(
                new HttpHost("124.70.91.221", 9200, "http"));
        //配置超时回调接口、
        builder.setRequestConfigCallback(
                requestConfigBuilder -> {
                    log.error("es请求超时...");
                    return requestConfigBuilder
                            //连接时间
                            .setConnectTimeout(50000)
                            //客户端时间
                            .setSocketTimeout(100000);
                });
        return new RestHighLevelClient(builder);
    }

}
